import { getEditor } from "./test.ts";
import { assertEquals, assertNotEquals } from "jsr:@std/assert";
Deno.test("undo redo test", async () => {
  //初始化editor

  const editor = getEditor();
  const tr = editor.tr;
  const stateNew = editor.state;
  //第一次事务
  await tr.asyncTransaction((doc) => {
    doc.attrs.value += 1;
    tr.setNodeAttribute("1", { name: "我是测试", email: "alice@example.com" });
  });
  editor.dispatch(tr);
  const stateNew1 = editor.state;
  assertNotEquals(stateNew, stateNew1);
  //第二次事务
  const tr1 = editor.tr;
  await tr1.asyncTransaction((_doc) => {
    tr1.setNodeAttribute("1", {
      name: "我是测试aaaaaaa",
      email: "alice@example.com",
    });
  });

  editor.dispatch(tr1);

  editor.undo();
  const stateNew2 = editor.state;
  assertEquals(stateNew1, stateNew2);
});
